;
define(["MComponent"], function(MComponent) {
	/**
	 * 卡片
	 * @param {Object} background 背景
	 */
	var MPCard = function(background) {
		this.dom = this.query("<div></div>","MPCard");
		this.setBackground(background);
		
		//水平阴影的位置 CSS3
		var hshadow = 2;
		
		//垂直阴影的位置 CSS3
		var vshadow = 2;
		
		//阴影模糊距离。 CSS3 + IE滤镜
		var blur = 3;
		
		//尺寸
		var spread = null;
		
		//阴影颜色 IE + CSS3
		var hexcolor = "#AAAAAA"//必须为6未颜色值。
		
		//CSS3 ,内部阴影
		var inset = null;
		
		//IE 方向角度
		var directions = [90,180];
		
		//透明度 IE + CSS3
		var opacity = null;
		
		/**
		 * 添加样式
		 */
		this.addStyle = function(key,val){
			this.setStyle(key, val);
			this.setStyle("-ms-"+key, val);
			this.setStyle("-moz-"+key, val);
			this.setStyle("-webkit-"+key, val);
			this.setStyle("-o-"+key,val );
		}
		
		/**
		 * 添加样式
		 */
		this.removeStyle = function(key){
			this.addStyle(key,"");
		}
		
		/**
		 * 设置水平阴影的位置 CSS3
		 */
		this.setHshadow = function(value){
			hshadow = value;
			return this;
		};
		
		/**
		 * 设置垂直阴影的位置 CSS3
		 */
		this.setVshadow = function(value){
			vshadow = value;
			return this;
		}
		
		/**
		 * 设置阴影模糊距离。
		 */
		this.setBlur = function(value){
			blur = value;
			return this;
		}
		
		/**
		 * 阴影的颜色
		 */
		this.setHexcolor= function(value){
			hexcolor = value;
			return this;
		}
		
		/**
		 * 设置CSS3 ,内部阴影
		 */
		this.setInset = function(value){
			inset = value;
			return this;
		}
		
		/**
		 * 设置阴影尺寸 CSS3 
		 */
		this.setSpread = function(value){
			spread = value;
			return this;
		}
		
		/**
		 * 设置IE的阴影方向
		 */
		this.setDirections = function(value){
			directions = value;
			return this;
		}
		
		/**
		 * 设置透明度
		 */
		this.setOpacity = function(value){
			opacity = value;
			return this;
		}
		
		/**
		 * 构造阴影
		 */
		this.buildShadow = function(){
			this.setBoxShadow(hshadow,vshadow,blur,spread,hexcolor,inset,directions,opacity);
		}
		
		/**
		 * hshadow 	必需。水平阴影的位置。允许负值。
		 * vshadow 	必需。垂直阴影的位置。允许负值。
		 * blur		可选。模糊距离。
		 * spread	可选。阴影的尺寸。
		 * hexcolor	可选。阴影的颜色。请参阅 CSS 颜色值。
		 * inset	可选。将外部阴影 (outset) 改为内部阴影。
		 * directions 可选。 IE专属
		 * opacity 可选。透明度
		 */
		this.setBoxShadow = function(hshadow,vshadow,blur,spread,hexcolor,inset,directions,opacity){
			//box-shadow:2px 2px 3px #aaaaaa;
			var boxstyles = [];
			
			if(hshadow){
				this.setHshadow(hshadow);
				boxstyles.push(hshadow + "px");
			}
			if(vshadow){
				this.setVshadow(vshadow);
				boxstyles.push(vshadow + "px");
			}
			if(blur){
				this.setBlur(blur);
				boxstyles.push(blur + "px");
			}
			if(spread){
				this.setSpread(spread);
				boxstyles.push(spread + "px");
			}
			if(hexcolor){
				this.setHexcolor(hexcolor);
				boxstyles.push(hexcolor);
			}
			if(inset){
				this.setInset(inset);
				boxstyles.push(inset);
			}
			
			if(opacity){
				
				if(opacity > 1){
					opacity = opacity / 100;
				}
				this.setOpacity(opacity);
				this.addStyle("opacity",opacity)
			}
			
			this.addStyle("box-shadow",boxstyles.join(" "));
			
			var that = this;
			var ie5 = function(){
				
				var styles = [];
				if(!directions){
					directions = [0,90,180,270]
				}
				
				for(var i in directions){
					var direction = directions[i];
					styles.push("progid:DXImageTransform.Microsoft.Shadow(color='"+hexcolor+"', Direction='"+direction+"', Strength='"+blur+"')");
				}
				if(opacity){
					
					if(opacity < 1){
						opacity = opacity * 100;
					}
					styles.push("progid:DXImageTransform.Microsoft.Alpha(Opacity='"+opacity+"')");
				}
//				alert(styles.join(" "));
				that.setStyle("filter",styles.join(" "));
				
			}
			
			mofum.ieCallback(ie5,ie5,ie5,null,ie5);
		}
		
		/**
		 * 清除阴影
		 */
		this.clearShadow = function(){
			this.removeStyle("box-shadow");
			this.removeStyle("filter");
		}
		
		this.init();
		
		this.init = function(){
//			this.buildShadow();
		};
		
		this.init();
	};
	mofum.extend(MPCard, MComponent);
	return MPCard;
});